<template>
	<view>

		<!-- identifyState  判断是否有身份 -->

			<view class="block__title">小区信息</view>
			
		<!-- 	<view class="cu-form-group">
				<text class="cuIcon-home text-green"></text>
				<view class="title">小区</view>
				{{plotNum?plotNum:""}}
			</view> -->
			<view class="cu-list menu">
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-home text-green"></text>
						<text class="text-grey">小区</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{plotName?plotName:""}}</text>
					</view>
				</view>
			</view>
			
			<view class="cu-list menu">
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-home text-green"></text>
						<text class="text-grey">小区编码</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{communityCode?communityCode:''}}</text>
					</view>
				</view>
			</view>

<!-- 			<view class="cu-form-group arrow" @tap="chooseCommunity">
				<text class="cuIcon-home text-green"></text>
				<view class="text-grey">小区</view>
				<input required readonly label="小区" v-model="plotNum" class="text-right" placeholder="请选择小区"
					name="plotNum" icon="arrow"></input>
				<text class='cuIcon-right'></text>
			</view> -->

			
			<view class="block__title">业主信息</view>
			<view class="cu-list menu">

				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-profile text-green"></text>
						<text class="text-grey">姓名</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{userInfo.name}}</text>
					</view>
				</view>
<!-- 				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-profile text-green"></text>
						<text class="text-grey">性别</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{ownInfo.sex == 0 ?"男":"女"}}</text>
					</view>
				</view> -->
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-profile text-green"></text>
						<text class="text-grey">年龄</text>
					</view>
					
					<view class="action" v-if="userInfo.age ==null || userInfo.age == '' || userInfo.age == undefined">
						<text class="text-grey text-sm"></text>
					</view>
					<view v-else>
						<view class="action">
							<text class="text-grey text-sm">{{userInfo.age}}</text>
						</view>
					</view>
				</view>
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-card text-green"></text>
						<text class="text-grey">身份证</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{userInfo.identityCard}}</text>
					</view>
				</view>
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-phone text-green"></text>
						<text class="text-grey">手机号</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{userInfo.phone}}</text>
					</view>
				</view>
				<view class="cu-item" style="width: 100%;">
					<view class="content" style="width: 30%;">
						<text class="cuIcon-phone text-green"></text>
						<text class="text-grey">名下房产</text>
					</view>
					<view class="action" style="width: 70%;float: right;text-align: right;">
						<text class="text-grey text-sm">{{userInfo.housePropertyList}}</text>
					</view>
				</view>
				<view class="cu-item" style="width: 100%;">
					<view class="content" style="width: 30%; ">
						<text class="cuIcon-phone text-green"></text>
						<text class="text-grey">名下车场</text>
					</view>
					<view class="action" style="width: 70%; float: right;text-align: right;" >
						<text class="text-grey text-sm">{{userInfo.automobileList}}</text>
					</view>
				</view>
				<!-- 				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-phone text-green"></text>
						<text class="text-grey">钱包</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{userInfo.wallet}}</text>
					</view>
				</view> -->
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-phone text-green"></text>
						<text class="text-grey">优惠券</text>
					</view>
					<view class="action">
						<text class="text-grey text-sm">{{userInfo.coupons}}</text>
					</view>
				</view>
			</view>


	</view>
</template>

<script>
	import {
		saveOwnerStorage,
	} from '../../lib/java110/utils/StorageUtil.js'
	// pages/viewBindOwner/viewBindOwner.js
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant;

	export default {
		data() {
			return {
				userPhone:'',
				bindUserInfo:'',  //用户绑定身份信息
				active: 0,
				plotNum: '', //小区
				plotCommunityId: '',
				userInfo: '',
				identifyState: '', //绑定状态
				communityCode:'',
				userId:'',
				sex: '',
				sexId: '',
				ownType: "", //选择的类型
				ownId: '',
				ownTel: '',
				proprietorName: '',
				plotName:'',
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			let that = this;
			// that.loadOwnerInfo();
			that.loadBind()
			that.userInfo = uni.getStorageSync("commonUser");
			console.log("个人中心",that.userInfo)
			that.userId = that.userInfo.id
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			// let owner = uni.getStorageSync("commonUser");
			// this.ownerId = owner.id
			
			let _plotNum = uni.getStorageSync("_selectCommunity");
			this.plotName = _plotNum.communityName ;
			this.communityCode = _plotNum.communityCode ;

			if (_plotNum != null && _plotNum != undefined && _plotNum != '') {
				this.plotNum = _plotNum.communityName + "小区";
				this.plotCommunityId = _plotNum.id; //小区id
				console.log("小区ID", this.plotCommunityId)
			}
		},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			loadBind(){
				this.bindUserInfo = uni.getStorageSync('bindUserInfo')
			},

			// 选择小区
			chooseCommunity: function(e) {
				console.log('点击调用了', e);
				uni.navigateTo({
					url: '/pages/viewCommunitys/viewCommunitys'
				});
			},

			// 查询绑定信息
			// loadOwnerInfo: function() {
			// 	let phoneNumber = uni.getStorageSync("userInfo")
			// 	this.userPhone = phoneNumber.phone;
			// 	let fountInfor = uni.getStorageSync("_selectCommunity");
			// 	if (fountInfor != null && fountInfor != undefined && fountInfor != '') {
			// 		this.plotCommunityId = fountInfor.id; //小区id
			// 	}
			// 	console.log("小区",this.plotCommunityId)
			// 		uni.request({
			// 			url: constant.url.ownerInfo,
			// 			header: context.getHeaders(),
			// 			method: "GET",
			// 			data: {
			// 				phone:this.userPhone, //业主id
			// 				// plotCommunityId: this.plotCommunityId, //小区id
			// 			},
			// 			success: (res) => {
			// 				this.ownInfo = res.data.result
			// 				console.log("res", this.ownInfo)
			// 			},
			// 			fail: function(e) {
			// 				wx.showToast({
			// 					title: "服务器异常了",
			// 					icon: 'none',
			// 					duration: 2000
			// 				});
			// 			}
			// 		});
			// },
			// 选择身份
			roomChange: function(e) {
				this.ownType = this.ownCloums[e.detail.value].ownType;
				this.ownId = this.ownCloums[e.detail.value].id; //当前身份Id
				console.log("this.ownId", this.ownId)
			},

			// 提交鉴定信息
			submitBtn: function(e) {
				let that = this
				let obj = {
					"communityId": that.plotCommunityId,
					"id": that.userPhone,
					"phone": that.ownTel,
					"proprietorName": that.proprietorName,
					"sex": that.sexId,
				};
				let msg = "";

				if (obj.proprietorName == "") {
					msg = "请填写姓名";
				// } else if (obj.proprietorRole == "") {
				// 	msg = "请选择身份类型";
				} else if (obj.tel == '') {
					msg = "请填写手机号";
				} else if (obj.communityId == "") {
					msg = "请选择小区";
				} else if (obj.phone == "") {
					msg = "请填写手机号";
				}

				if (msg != "") {
					wx.showToast({
						title: msg,
						icon: 'none',
						duration: 2000
					});
				} else {
					console.log("提交数据", obj);
					uni.request({
						url: constant.url.bindOwner,
						header: context.getHeaders(),
						method: "POST",
						data: obj,
						//动态数据
						success: function(res) {
							that.bindUserInfo = res.data.data;
							uni.setStorageSync('bindUserInfo', that.bindUserInfo);
							let _json = res.data;
							if (_json.code == 0) {
							uni.redirectTo({
								url: '/pages/viewBindOwner/viewBindOwner',
							});
							return;
							}
							wx.showToast({
								title: "服务器异常了",
								icon: 'none',
								duration: 2000
							})
						},
						fail: function(e) {
							console.log(e);
							wx.showToast({
								title: "服务器异常了",
								icon: 'none',
								duration: 2000
							});
						}
					});
				}
			},
		}
	};
</script>
<style lang="scss" scoped>
	@import "./viewBindOwner.css";

	.contenter {
		width: 100%;
		height: calc(100vh - 100rpx);
		overflow: auto;
	}

	.subBtn {
		osition: relative;
		display: flex;
		justify-content: center;
		align-items: center;

		button {
			width: 350rpx;
			height: 70rpx;
			border-radius: 30rpx;
			text-align: center;
			line-height: 70rpx;
			// font-size: ;
		}
	}

	text {
		text-align: center;
	}

	/deep/ .cu-form-group>text[class*="cuIcon-"] {
		font-size: 36rpx;
		box-sizing: border-box;
		padding: 0rpx 11rpx;
	}
	/deep/ .cu-list+.cu-list{
		margin: 0rpx;
	}
</style>
